package com.itheima.dubbo.mysql.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.itheima.commons.model.domain.UserFreeze;
import com.itheima.dubbo.interfaces.UserFreezeApi;
import com.itheima.dubbo.mysql.mapper.UserFreezeMapper;
import org.springframework.beans.factory.annotation.Autowired;

import java.sql.Wrapper;

/*
 * @ProjectName:project-exercise
 * @Package:com.itheima.dubbo.mysql.impl
 * @ClassName:UserFreezeImpl
 * @Author:ZHANG
 * @Date:2021-12-19 10:48
 * @Description:
 */
@Service
public class UserFreezeImpl implements UserFreezeApi {
    @Autowired
    private UserFreezeMapper userFreezeMapper;

    @Override
    public void updateUserFreezeInfo(Long userId, String freezingTime, String freezingRange, String reasonsForFreezing, String frozenRemarks) {
        userFreezeMapper.update(UserFreeze.builder()
                .freezingTime(freezingTime)
                .freezingRange(freezingRange)
                .reasonsForFreezing(reasonsForFreezing)
                .frozenRemarks(frozenRemarks).build(),
                Wrappers.lambdaQuery(UserFreeze.class).eq(UserFreeze::getUserId,userId));
    }

    @Override
    public void insertUserFreezeInfo(Long userId, String freezingTime, String freezingRange, String reasonsForFreezing, String frozenRemarks) {
        UserFreeze userFreeze = new UserFreeze(null,userId,freezingTime,freezingRange,reasonsForFreezing,frozenRemarks);
        userFreezeMapper.insert(userFreeze);
    }

    @Override
    public void unFreezeUser(Long userId, String reasonsForThawing) {
        userFreezeMapper.update(UserFreeze.builder()
                        .reasonsForFreezing(" ")
                        .freezingTime(" ")
                        .freezingRange(" ")
                        .frozenRemarks(reasonsForThawing).build(), Wrappers.lambdaQuery(UserFreeze.class).eq(UserFreeze::getUserId,userId));
    }

    @Override
    public UserFreeze queryUserFreezeInfo(Long userId) {
        return userFreezeMapper.selectOne(Wrappers.lambdaQuery(UserFreeze.class).eq(UserFreeze::getUserId, userId));
    }
}
